<%@ page contentType ="text/html; charset=UTF-8"%>
<%@ page import="java.sql.*, java.util.*" %>

<% request.setCharacterEncoding("euc-kr"); %>
<jsp:include page="header.jsp"/>


<jsp:include page="aside_cafe.jsp"/>

	<article>
<%

String pageNum = request.getParameter("pageNum");
if(pageNum == null)
{
	pageNum = "1";
}

int listSize = 20;
int currentPage = Integer.parseInt(pageNum);
int StartRow = currentPage * listSize - listSize;
int maxRow;

Class.forName("com.mysql.jdbc.Driver");

Connection conn = null;
PreparedStatement pstmt = null;
Statement stmt = null;
ResultSet rs = null;

try{
	String jdbcDriver ="jdbc:mysql://192.168.0.120:3306/coffee?" +
			"useUnicode=true&characterEncoding=euckr";
String dbUser="root";
String dbPass="123456";

	
	conn = DriverManager.getConnection(jdbcDriver, dbUser, dbPass);
	
	stmt = conn.createStatement();
	
	String strSQL = "select * from evboard order by num DESC";
	
	//rs = stmt.executeQuery(strSQL);
%>

<div id="list">
<table border="0" width="800" cellpadding="0" cellspacing="0">
<tr>
	<td><hr size="1" noshad></td>
</tr>		
</table>
<table border="0" cellspacing="1" cellpadding="2" width="800">
<tr bgcolor="cccccc">
	<td><center><b>번호</b></center></td>
	<td><center><b>제목</b></center></td>
	<td><center><b>작성일</b></center></td>
	
</tr>
<%
strSQL = "select count(*) from evboard";
rs = stmt.executeQuery(strSQL);
rs.next();
maxRow = rs.getInt("count(*)");
//System.out.println(maxRow);

strSQL = "select * from evboard order by num desc limit " + StartRow + ", " + listSize;
rs = stmt.executeQuery(strSQL);

for(int i=0; i<listSize; i++){
if(rs.next()){
	int num = rs.getInt("num");
	String title = rs.getString("title");
	String writedate = rs.getString("writedate");
	
%>
<tr bgcolor="ededed">
	<td align="center"><font color="black">
	<%=num %>
	</td>
	<td align="center">
		<a href="event_output.jsp?num=<%=num %>">
		<font color="black"><%=title %></font></a>
	</td>
	
	<td align="center"><%=writedate %>
	</td>
	
<%
	}
}
%>
</table>
<table border="0" width="800" cellpadding="0" cellspacing="0">
<tr>
	<td><hr size="1" noshade>
	</td>
</tr>
</table>
<table border="0" width="800">
<tr>
	<td align="left">
	</td>
	<td align="right">
	<a href="admin/eventwrite.jsp">[등록]</a>
	</td>
</tr>
</table>
<div id='page'>
<%

int setPage=1;
int lastPage=0;
lastPage = maxRow / listSize + 1;


while(setPage <= lastPage)
{
%>
	<a href="event01.jsp?pageNum=<%=setPage %>">[<%=setPage %>]</a>
<%	
	setPage = setPage + 1;
}

}catch(SQLException ex){
	out.println(ex.getMessage());
}finally{
	if(rs != null) try{rs.close();} catch(SQLException ex){}
	if(stmt != null) try{stmt.close();} catch(SQLException ex){}
	if(conn != null) try{conn.close();} catch(SQLException ex){}
}

%>
</div>
</div>
</article>

<jsp:include page="footer.jsp"/>